#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<unordered_set>
using namespace std;
unordered_set<string> us;
const int N = 6;
int g[N][N];
int n, m, k;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
void dfs(int x, int y, string s, int cnt)
{
    if (cnt == 0)
    {
        us.insert(s);
        return;
    }
    for (int i = 0; i < 4; i++)
    {
        int a = x + dx[i], b = y + dy[i];
        if (a<1 || a>n || b<1 || b>m) continue;
        dfs(a, b, s + to_string(g[a][b]), cnt - 1);
    }
}
int main()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> g[i][j];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            dfs(i, j, to_string(g[i][j]), k);
        }
    }
    cout << us.size() << endl;
    return 0;
}